package com.hsnn.medstgmini.common.controller;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.imageio.ImageIO;

import org.apache.commons.io.FileUtils;

public class FIleImage {

	public static void main(String[] args) throws Exception {
		String uploadPath = "C:/upload/";
		String path = "C:/upload/xxxx.jpg";
		File file = new File(path);
    	InputStream stream = new FileInputStream(file);
	    BufferedImage bi = ImageIO.read(stream);
		System.out.println( bi.getWidth());
		System.out.println( bi.getHeight());
		
		BufferedImage buffImg = new BufferedImage(500, 300, BufferedImage.TYPE_INT_RGB);  
		//buffImg.getGraphics().drawImage(bi.getScaledInstance(500, 300,Image.SCALE_SMOOTH), 0,0, null);  
		buffImg.getGraphics().drawImage(bi, 0,0, null);
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ImageIO.write(buffImg,"JPG", os);
		InputStream str =  new ByteArrayInputStream(os.toByteArray());
	     
	    String filename = "aaaa.jpg";// 文件名称
		String filePaths = uploadPath + filename;
		File destFile = new File(filePaths);
		FileUtils.copyInputStreamToFile(str, destFile);
		
		
		String paths = "C:/upload/aaaa.jpg";
		File files = new File(paths);
    	InputStream streams = new FileInputStream(files);
	    BufferedImage bis = ImageIO.read(streams);
		System.out.println( bis.getWidth());
		System.out.println( bis.getHeight());
		
		
		
	}
}
